import Orange
from orngWrap import PreprocessedLearner
from Orange.OrangeWidgets.OWWidget import OWWidget, Multiple
from Orange.OrangeWidgets.OWBaseWidget import AttributeList
from Orange.OrangeWidgets import OWGUI
from PyQt4.QtGui import QApplication, QIntValidator, QLabel, QWidget, QFormLayout, QAbstractButton, QDoubleValidator, QTableWidget, QClipboard, QStandardItemModel, QStandardItem, QIcon, QHeaderView, QCheckBox, QVBoxLayout
from PyQt4.QtCore import QObject, Qt, pyqtSignal, QString
from PyQt4 import QtCore, QtGui, uic
import os
import sys
import abc
import inspect
import types
# optimization imports
from Goldenberry.optimization.base.GbCostFunction import *
from Goldenberry.optimization.base.GbSolution import GbSolution
from Goldenberry.base.GbDynamicFunction import *
from Goldenberry.classification.base.GbKernel import GbKernel
from Goldenberry.classification.base.GbFactory import GbFactory
import Goldenberry.classification.Kernels as Kernels
from Goldenberry.optimization.base.GbBaseOptimizer import *
from Goldenberry.optimization.edas.GbBlackBoxTester import GbBlackBoxTester
import Goldenberry.optimization.cost_functions as cost_functions
from Goldenberry.optimization.edas.Univariate import Cga, Pbil, Tilda, Pbilc
from Goldenberry.optimization.edas.Bivariate import Bmda, DependencyMethod
from Goldenberry.feature_selection.WKiera import *
# GA modifications
from Goldenberry.optimization.base.GbSolution import GbIndividual
import Goldenberry.optimization.ga.GbSolutionRepMgr.BinaryEncoders as binary_encoders
import Goldenberry.optimization.ga.GbSolutionRepMgr.RealEncoders as real_encoders
import Goldenberry.optimization.ga.GbSelectorMgr.Selectors as selection_functions
import Goldenberry.optimization.ga.GbMutatorMgr.RealMutators as real_mutation_functions
import Goldenberry.optimization.ga.GbMutatorMgr.BinaryMutators as binary_mutation_functions
import Goldenberry.optimization.ga.GbCrossoverMgr.RealCrossers as real_xover_functions
import Goldenberry.optimization.ga.GbCrossoverMgr.BinaryCrossers as binary_xover_functions
from Goldenberry.optimization.ga.GbCrossoverMgr.Crosser import Crosser
from Goldenberry.optimization.ga.GbInitPopMgr.InitPop import InitPop
from Goldenberry.optimization.ga.GbMutatorMgr.Mutator import Mutator
from Goldenberry.optimization.ga.GbSelectorMgr.Selector import Selector
from Goldenberry.optimization.ga.GbSolutionRepMgr.SolutionRep import SolutionRep
from Goldenberry.optimization.ga.GbGaMgr.GeneticAlgorithm import GeneticAlgorithm

from Goldenberry.optimization.ga.DataType.SolutionRepParams import SolutionRepParams
from Goldenberry.optimization.ga.DataType.InitPopParams import InitPopParams

# end GA modifications
# classification imports
from Goldenberry.classification.Perceptron import PerceptronLearner, PerceptronClassifier

def load_widget_ui(widget):
    """Loads the widget's QT Ui file (widget.ui). The file must be located in the same
    directory of the widget and with the same name with the .ui extension."""
    widget_type = type(widget)
    path = os.path.dirname(inspect.getfile(widget_type)) + "/" + widget_type.__name__ + ".ui"
    if os.path.isfile(path):
        print "xx0"
        widget.controlArea = uic.loadUi(path, widget)
        print "xx1"
    else:
        raise Exception("Ui file not found for widget: " + str(widget))